home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / cthugha5.zip / CTHU5SRC.ZIP / SB_DRIVE.H < prev    next >
C/C++ Source or Header  |  1994-08-19  |  10KB  |  335 lines

  1. /* Soundblaster Digital Audio library for Borland C++. *
  2.  *                                                                 *
  3.  * Note: All variables defined in this header are      *
  4.  * read only. Don't change unless you know what you     *
  5.  * are doing!                                          */
  6.  
  7. /* Structure definitions */
  8.  
  9. struct dsp_device_caps
  10. {
  11.     unsigned min_speed;
  12.  
  13.     unsigned max_8bit;
  14.     unsigned max_8bit_s;
  15.  
  16.     unsigned max_16bit;
  17.     unsigned max_16bit_s;
  18.  
  19.     unsigned    max_8bit_rec;
  20.     unsigned max_8bit_rec_s;
  21.  
  22.     unsigned    max_16bit_rec;
  23.     unsigned max_16bit_rec_s;
  24.  
  25.     char        supports_signed;
  26. };
  27.  
  28.  
  29. /* Port offsets from base address */
  30.  
  31. #define MixAddrOffset        0x04
  32. #define MixDataOffset        0x05
  33.  
  34. #define FMAddrOffset            0x08
  35. #define FMDataOffset            0x09
  36. #define FMStatOffset            0x08
  37.  
  38. #define DSPResetOffset        0x06
  39. #define DSPReadOffset        0x0A
  40. #define DSPWriteOffset        0x0C
  41. #define DSPRStatOffset        0x0E
  42. #define DSPIrqAck8Offset    0x0E
  43. #define DSPIrqAck16Offset    0x0F
  44.  
  45. /* Macros for port addresses */
  46.  
  47. #define MixAddrPort            (SBport+MixAddrOffset)
  48. #define MixDataPort            (SBport+MixDataOffset)
  49.  
  50. #define FMAddrPort           (SBport+FMAddrOffset)
  51. #define FMDataPort            (SBport+FMDataOffset)
  52. #define FMStatPort            (SBport+FMStatOffset)
  53.  
  54. #define DSPResetPort            (SBport+DSPResetOffset)
  55. #define DSPReadPort          (SBport+DSPReadOffset)
  56. #define DSPWritePort            (SBport+DSPWriteOffset)
  57. #define DSPRStatPort            (SBport+DSPRStatOffset)
  58. #define DSPIrqAck8Port        (SBport+DSPIrqAck8Offset)
  59. #define DSPIrqAck16Port        (SBport+DSPIrqAck16Offset)
  60.  
  61. /* Mixer source values for high-level mixer control */
  62.  
  63. #define MIXmaster             0
  64. #define MIXvoice                1
  65. #define MIXfm                    2
  66. #define MIXline                3
  67. #define MIXcd                    4
  68. #define MIXgain                5
  69. #define MIXtreble                6
  70. #define MIXbass                7
  71.  
  72. #define MIXin_gain            8
  73.  
  74. #define MIXmicrophone      9
  75. #define MIXspeaker         10
  76.  
  77. #define MIXleft                1
  78. #define MIXright                2
  79. #define MIXboth                3
  80.  
  81. /* Mixer output controls for SB16 */
  82.  
  83. #define CD_OUT                    6
  84. #define LINE_OUT                24
  85. #define MIC_OUT                1
  86.  
  87. #define CD_OUT_L                4
  88. #define CD_OUT_R                2
  89.  
  90. #define LINE_OUT_L            16
  91. #define LINE_OUT_R            8
  92.  
  93. /* Mixer input controls for SB16 */
  94.  
  95. #define FM_IN                    0x60
  96. #define LINE_IN                0x18
  97. #define CD_IN                    0x06
  98.  
  99. #define MIC_IN                    0x01
  100.  
  101. #define FM_IN_L                0x40
  102. #define FM_IN_R                0x20
  103.  
  104. #define LINE_IN_L                0x10
  105. #define LINE_IN_R                0x08
  106.  
  107. #define CD_IN_L               0x04
  108. #define CD_IN_R                0x02
  109.  
  110. #ifndef SB_DRIVE
  111. extern int     SBport;
  112. extern int     SBirq;
  113. extern int  SBdma;
  114. extern int    SBdma16;
  115.  
  116. extern int     SBtype;
  117. #endif SB_DRIVE
  118.  
  119. /* High level interface routines follow. */
  120.  
  121. #define dsp_sample_out(x) { SbWriteByte(DSPSendOneSample); SbWriteByte(x); }
  122.         /* Send one sample directly to the audio DAC. Mono 8-bit only. */
  123.  
  124. int dsp_reset(void);
  125.         /* Returns Soundblaster found:     0=none
  126.          *                                            1=Soundblaster 1.x         *
  127.          *                                            2=Soundblaster 2.0         *
  128.          *                                            3=Soundblaster Pro         *
  129.          *                                            4=Soundblaster 16/16 ASP   *
  130.          *                                            5=Unknown                  */
  131.  
  132. int dsp_version(void);
  133.         /* Returns the DSP revision of the Soundblaster */
  134.  
  135. #define dsp_set_playback(a,b,c,d) dsp_set_sample(a,b,c,d)
  136.         /* Alternate name for dsp_set_sample                              */
  137.  
  138. unsigned dsp_set_record(unsigned speed, int stereo, int bits, int sign);
  139.         /* Returns 0 if recording is impossible, actual rate otherwise.   */
  140.  
  141. unsigned dsp_set_sample(unsigned speed, int stereo, int bits, int sign);
  142.         /* returns the actual speed, or 0 if invalid for current hardware *
  143.          * note: 0 response applies to playback _only_. A successful      *
  144.          * execution of this procedure does NOT ensure the card's ability *
  145.          * to record at that rate.                                        */
  146.  
  147. void dsp_set_speed(unsigned *speed);
  148.         /* resets parameter to actual speed */
  149.  
  150. int dsp_read(void *data);
  151.         /* Reads data from digital sampling into *data.                   *
  152.          * Possible returns: 0  complete success     (data in *data)        *
  153.          *                   1  overrun              (data in *data)      *
  154.          *                   2  starting fresh DMA                        *
  155.          *                   3  waiting for data                          *
  156.          *                   4  termination requested                     *
  157.  
  158.          * Call with data == NULL to terminate read DMAs.                       */
  159.  
  160. int dsp_write(void *sample_buf);
  161.         /* returns 0 if buffers are full, or 1 if write was successful.   *
  162.          * The buffer will be played in its entirity; make sure you send  *
  163.          * a complete DMA buffer's worth of data. Use NULL to start play  *
  164.          * back of what is already in DMA buffers.                        */
  165.  
  166. int dsp_prewrite(void *sample_buf);
  167.         /* adds sample_buf to the DMA playback queue without starting     *
  168.          * digital playback. Allows you to fill the queue in advance of   *
  169.          * starting. Returns a 0 when one buffer is left. Use dsp_write   *
  170.          * to start playback.                                                             */
  171.  
  172. void *dsp_open_buf(void);
  173.         /* returns a pointer to the free next data buffer, to be filled   *
  174.          * by the calling software. Faster than dsp_write.                */
  175.  
  176. void dsp_close_buf(void);
  177.         /* signals to the Soundblaster driver that you have finished      *
  178.          * filling the buffer returned by dsp_open_buf. filled is either  *
  179.          * zero, to return the buffer unfilled, or 1, if it has been      *
  180.          * has been completely filled. Partial buffers are not supported. */
  181.  
  182. int dsp_buffers_free(void);
  183.         /* returns number of free buffers. */
  184.  
  185. void dsp_callback(void (*handler)(void));
  186.         /* called whenever a buffer is finished playing. NULL to disable. */
  187.  
  188. int dsp_open(int port, int dma, int irq, int dma16, unsigned bufsize, unsigned numbufs);
  189.         /* returns 0 if insufficient memory is available, or the   *
  190.          * type of soundblaster found per the previous table.      *
  191.          * Bufsize ranges from 1K to 31K, numbuf from 2 to 16.      *
  192.          * No more than 63K total can be allocated for DMA.         */
  193.  
  194. struct dsp_device_caps *dsp_get_device_caps(void);
  195.         /* Returns capabilities of Soundblaster installed in computer. */
  196.  
  197. void dsp_close(void);
  198.         /* turn off the speaker, reset the DSP, free memory buffers. */
  199.  
  200. void dsp_speaker(int status);
  201.         /* turn the DSP speaker on and off... nonfunctional on SB16 */
  202.  
  203. void dsp_pause_dma(void);
  204.         /* Suspend Soundblaster DMA output */
  205.  
  206. int dsp_continue_dma(void);
  207.         /* Resume suspended DMA. Checks to see if you should be first    *
  208.          * Returns 1 if successful, 0 if no data to play.                */
  209.  
  210. int dsp_active(void);
  211.         /* Returns 1 if the DSP is currently busy playing or recording,  *
  212.          * 0 if it is not. (This returns 0 if the DSP buffers are primed *
  213.        * but not playing yet.)                                         */
  214.  
  215. int mix_reset(void);
  216.         /* Resets mixer to default values; returns 1 if mixer is active. *
  217.          * Note: It's not polite to reset the mixer unannounced.         */
  218.  
  219. void mix_write(int device, int channel, unsigned char level);
  220.         /* devices and channels listed above, level 0-255. */
  221.  
  222. unsigned char mix_read(int device, int channel);
  223.         /* returns 0-255, MIXboth returns average of two channels. */
  224.  
  225. void    mix_set_output(int value);
  226.         /* Use output values listed above... add together all relevent. *
  227.          * Only relevant to Soundblaster 16.                            */
  228.  
  229. void    mix_set_input(int value);
  230.  
  231. void  mix_set_sb16_output(int channel, int value);
  232.  
  233. void  mix_set_sb16_input( int channel, int value);
  234.  
  235. int sb_get_params(int *port, int *dma, int *irq, int *dma16);
  236.         /* returns values contained in the BLASTER environent string */
  237.  
  238. /* Low level interface functions and data definitions follow. */
  239.  
  240. #ifndef SB_DRIVE
  241. extern int SBTimeOut;                                /* Timeout value for Soundblaster */
  242. extern unsigned char SBProMixRegs[];           /* Mixer register addresses for Soundblaster Pro */
  243. extern unsigned char SB16MixRegs[];                /* Mixer register addresses for Soundblaster 16 */
  244.  
  245. extern int SBintnum;
  246.  
  247. extern int SBTimeOut;                              /* time to wait for DSP response */
  248.  
  249. extern char SbOK;
  250.  
  251. extern char *DMABufferBase;
  252. extern char *DMABuffers[16];
  253.  
  254. extern unsigned DMABufPage[16];
  255. extern unsigned DMABufOffset[16];
  256.  
  257. extern unsigned BufLen;
  258. extern unsigned BufCount;
  259.  
  260. extern char BufQueueHead;
  261. extern char BufQueueTail;
  262.  
  263. extern void *old_irq_handler;
  264.  
  265. extern volatile int dsp_overrun;                    // Incremented on a record overrun
  266. #endif
  267.  
  268. /* Soundblaster Basic commands */
  269. #define DSPSendOneSample    0x10
  270. #define DSPGetOneSample        0x20
  271.  
  272. #define DSPStartDMA            0x14
  273. #define DSPStartADCDMA        0x24
  274.  
  275. #define DSPSpeakerOn            0xD1
  276. #define DSPSpeakerOff        0xD3
  277.  
  278. #define DSPGetVersion        0xE1
  279. #define DSPGetCopyright        0xE3
  280.  
  281. #define DSPSetTimeConstant 0x40
  282.  
  283. #define DSPPauseDMA            0xD0
  284. #define DSPContinueDMA        0xD4
  285.  
  286. /* Soundblaster 2.0 and Pro commands */
  287. #define DSPSetHSDMASize        0x48
  288. #define DSPStartHSDMA        0x91
  289.  
  290. #define DSPStartHSADCDMA    0x99
  291.  
  292. /* Soundblaster Pro commands */
  293.  
  294. #define DSPSBProADCStereo    0xA8
  295. #define DSPSBProADCMono        0xA0
  296.  
  297. /* Soundblaster 16 commands */
  298. #define DSPSB16SetSpeed            0x42
  299.  
  300. #define DSPSB16Start16DMA        0xB6
  301. #define DSPSB16Start8DMA        0xC6
  302.  
  303. #define DSPSB16Start16ADCDMA  0xBE
  304. #define DSPSB16Start8ADCDMA    0xCE
  305.  
  306. #define DSPSB16Stereo            0x20
  307. #define DSPSB16Mono                0x00
  308.  
  309. #define DSPSB16StereoSign      0x30
  310. #define DSPSB16MonoSign        0x10
  311.  
  312. #define DSPSB16Pause16DMA      0xD9
  313. #define DSPSB16Pause8DMA       0xDA
  314.  
  315. #define DSPSB16Cont16DMA        0x47
  316. #define DSPSB16Cont8DMA            0x45
  317.  
  318. /* Low level interface routines follow */
  319.  
  320. void SbWriteByte(unsigned char command);      /* write one byte to the DSP */
  321. unsigned char SbReadByte(unsigned timeout);    /* receive one byte from DSP */
  322.  
  323. void SbWriteByteTimeout(unsigned char command, unsigned timeout);
  324.  
  325. void SbWriteMixerReg(unsigned char reg, unsigned char value);
  326. unsigned char SbReadMixerReg(unsigned char reg);
  327.  
  328. void interrupt new_irq_handler(void);
  329.  
  330. void EnableIRQ(char irq);
  331. void DisableIRQ(char irq);
  332.  
  333.  
  334.  
  335.